package com.gpframework.module.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gpframework.common.enums.YesNoEnum;
import com.gpframework.module.common.domain.CommonResource;
import com.gpframework.module.common.domain.req.CommonResourceReq;
import com.gpframework.module.common.domain.vo.CommonResourceVo;
import com.gpframework.module.common.mapper.CommonResourceMapper;
import com.gpframework.module.common.service.ICommonResourceService;
import com.gpframework.module.module.domain.req.BrandStoreReq;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @ClassName CommonResource
 * @Author gpframework
 * @Date 2022-04-07
 * @Version 1.0.0
 * @Description 资源Service业务层处理
 */
@Service
public class CommonResourceServiceImpl extends ServiceImpl<CommonResourceMapper, CommonResource> implements ICommonResourceService {

    /**
     * @Description 查询列表返回VO 用于返回给前端的列表接口
     * @Author gpframework
     * @Date 2022-04-07
     * @Param [lqw]
     * @Return List<CommonResourceVo>
     */
    @Override
    public List<CommonResourceVo> listVo(QueryWrapper<CommonResource> lqw) {
        return this.baseMapper.listVo(lqw);
    }

    /**
     * @Description 通过查询详情VO 用于返回给前端的列详情接口
     * @Author gpframework
     * @Date 2022-04-07
     * @Param [id]
     * @Return CommonResourceVo
     */
    @Override
    public CommonResourceVo getVoById(Long id) {
        return this.baseMapper.getVo(id);
    }

    /**
     * 删除资源
     *
     * @param resourceReq
     * @return
     */
    @Override
    public boolean del(CommonResourceReq resourceReq) {
        int i = this.baseMapper.del(resourceReq);
        return i > 0;
    }

    /**
     * 保存附件
     *
     * @param commonResource
     * @return
     */
    @Override
    public int addOrUpdate(CommonResource commonResource) {
        CommonResourceReq commonResourceReq = new CommonResourceReq();
        commonResourceReq.setBrandId(commonResource.getBrandId());
        commonResourceReq.setBusinessId(commonResource.getBusinessId());
        commonResourceReq.setBusinessType(commonResource.getBusinessType());
        this.del(commonResourceReq);
        return this.baseMapper.insert(commonResource);
    }

    /**
     * 根据业务id查询
     *
     * @param scheduleId
     * @return
     */
    @Override
    public List<CommonResourceVo> findByBusinessId(Long scheduleId) {
        QueryWrapper<CommonResource> lqw = new QueryWrapper();
        lqw.eq("gp.business_id", scheduleId);
        lqw.eq("gp.del_status", YesNoEnum.NO.getKey());
        return this.baseMapper.listVo(lqw);
    }

    /**
     * 获取员工附件缩略图
     *
     * @param brandStoreReq
     * @return
     */
    @Override
    public Set<String> getEmployeesThumb(BrandStoreReq brandStoreReq) {
        return this.baseMapper.getEmployeesThumb(brandStoreReq);
    }
}
